package com.hly.tool.string;

import com.matrixone.apps.domain.util.MapList;

import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * @author ：Jack Hao
 * @date ：Created in 2021/7/14 18:24
 * @description：
 */
public class StringUtil {





    /**
     * @return void
     * @Author HLY
     * @CreateTime 2023/10/10
     * @Description: 测试文件特殊文件名替换成下划线
     */
    private String fileNameHandler(String str) {
        //      1.文件名在操作系统中不允许出现  / \ " : | * ? < > 故将其以空替代
//        String fileName = "ss/ff\\*gg?hh<jj>kk.txt";
        Pattern pattern = Pattern.compile("[\\s\\\\/:\\*\\?\\\"<>\\|]");
        Matcher matcher = pattern.matcher(str);
        return matcher.replaceAll("_"); // 将匹配到的非法字符以空替换
    }

    /**
     * 获取指定长度随机数
     *
     * @param len
     * @return
     */
    public static String getRandom(int len) {
        Random r = new Random();
        int bitNum = 1;
        for (int i = 0; i < len; i++) {
            bitNum = bitNum * 10;
        }
        long num = Math.abs(r.nextLong() % (bitNum));
        String s = String.valueOf(num);
        for (int i = len - s.length(); i > 0; i--) {
            s = "0" + s;
        }
        if (s.length() > len) {
            s = s.substring(0, len);
        }
        return s;
    }
}
